#pragma once

#include <stdint.h>
#include <functional>
#include <memory>

namespace nio {

	class Task
	{
	private:
		bool repeated = false;
		bool cancelled = false;
		int64_t nextTime = 0;
		int64_t interval = 0;
		std::function<void()> func = nullptr;
	public:
		Task(int64_t interval, bool repeated, std::function<void()> func);

		int64_t RemainTime();
		void Cancel();
		void Execute();
		bool tryFinish();

	};

	struct Task_cmp
	{
		bool operator ()(std::shared_ptr<Task> t1, std::shared_ptr<Task> t2) {
			return t1->RemainTime() > t2->RemainTime();
		}
	};

}